/*
* This file is a part of the open-eBackup project.
* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
* If a copy of the MPL was not distributed with this file, You can obtain one at
* http://mozilla.org/MPL/2.0/.
*
* Copyright (c) [2024] Huawei Technologies Co.,Ltd.
*
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
*/
#include <common/JsonHelper.h>
#include "common/Structs.h"
#include "ShowVolumeResponse.h"

namespace HcsPlugin {
ShowVolumeResponse::ShowVolumeResponse() {}

ShowVolumeResponse::~ShowVolumeResponse() {}

bool ShowVolumeResponse::Serial()
{
    if (m_body.empty()) {
        return false;
    }
    if (!Module::JsonHelper::JsonStringToStruct(m_body, m_volumeDetail)) {
        ERRLOG("Convert %s failed.", WIPE_SENSITIVE(m_body).c_str());
        return false;
    }
    if (!Module::JsonHelper::JsonStringToStruct(m_volumeDetail.m_hostVolume.m_osVolRepDriverData,
        m_volumeDetail.m_hostVolume.m_drvData)) {
        ERRLOG("Convert %s failed.", m_volumeDetail.m_hostVolume.m_osVolRepDriverData.c_str());
        return false;
    }
    m_volumeDetail.m_hostVolume.m_metadata = m_body;
    return true;
}

HSCVolDetail ShowVolumeResponse::GetHSCVolDetail() const
{
    return m_volumeDetail;
}

std::string ShowVolumeResponse::GetArch() const
{
    return m_volumeDetail.m_hostVolume.m_volImageMetadata.m_arch;
}

std::string ShowVolumeResponse::GetStatus() const
{
    return m_volumeDetail.m_hostVolume.m_status;
}

uint64_t ShowVolumeResponse::GetSize() const
{
    return m_volumeDetail.m_hostVolume.m_size;
}

std::vector<Attachments> ShowVolumeResponse::GetAttachPoints() const
{
    return m_volumeDetail.m_hostVolume.m_attachPoints;
}

std::string ShowVolumeResponse::GetDSType() const
{
    return m_volumeDetail.m_hostVolume.m_metaData.m_storageType;
}

std::string ShowVolumeResponse::GetVolId() const
{
    return m_volumeDetail.m_hostVolume.m_id;
}

std::string ShowVolumeResponse::GetName() const
{
    return m_volumeDetail.m_hostVolume.m_displayName;
}

std::string ShowVolumeResponse::GetLUNWWN() const
{
    return m_volumeDetail.m_hostVolume.m_metaData.m_lunWWN;
}

std::string ShowVolumeResponse::GetDSSN() const
{
    return m_volumeDetail.m_hostVolume.m_drvData.m_sn;
}

std::string ShowVolumeResponse::GetLUNID() const
{
    return m_volumeDetail.m_hostVolume.m_drvData.m_lunId;
}

std::string ShowVolumeResponse::GetVolBootable() const
{
    return m_volumeDetail.m_hostVolume.m_bootable;
}

std::string ShowVolumeResponse::GetStorageIp() const
{
    return m_volumeDetail.m_hostVolume.m_drvData.m_ip;
}

int32_t ShowVolumeResponse::GetPoolId() const
{
    return m_volumeDetail.m_hostVolume.m_drvData.m_pool;
}

std::string ShowVolumeResponse::GetVolNameOnStorage() const
{
    return m_volumeDetail.m_hostVolume.m_drvData.m_volName;
}

bool ShowVolumeDetailResponse::Serial()
{
    if (m_body.empty()) {
        return false;
    }
    if (!Module::JsonHelper::JsonStringToStruct(m_body, m_volumeDetailList)) {
        ERRLOG("Convert %s failed.", WIPE_SENSITIVE(m_body).c_str());
        return false;
    }
    return true;
}

VolumeDetailList ShowVolumeDetailResponse::GetHSCVolDetail() const
{
    return m_volumeDetailList;
}
}